import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/virtual-table' },
  {
    path: '/virtual-table',
    name: 'virtualTable',
    component: () => import('@/components/virtual-table.vue'),
    meta: {
      title: '虚拟表格',
    },
  },
  {
    path: '/vant',
    name: 'vant',
    component: () => import('@/components/vant/index.vue'),
    redirect: '/vant-tabs',
    children: [
      {
        path: '/vant-tabs',
        name: 'tabs',
        component: () => import('@/components/vant/tabs.vue'),
        meta: {
          title: 'tabs',
        },
      },
    ],
  },
  {
    path: '*', // 匹配任意路由
    redirect: '/virtual-table',
  },
]

const router = new VueRouter({
  routes,
})

router.afterEach((to) => {
  // 设置页面的标题
  document.title = to.meta.title
})

export default router
